home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / MUser17src.lha / MultiUser / src / Support / SetDefProtect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-07  |  3.7 KB  |  171 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Set the Default Protection Bits                                    *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <utility/tagitem.h>
  16. #include <libraries/multiuser.h>
  17. #include <proto/multiuser.h>
  18.  
  19. #include "SetDefProtect_rev.h"
  20.  
  21.  
  22. char __VersTag__[] = VERSTAG;
  23.  
  24.  
  25. #define FLAGS_OWNER    1
  26. #define FLAGS_GROUP    2
  27. #define FLAGS_OTHER    3
  28.  
  29.  
  30. static BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type,
  31.                                               struct DosLibrary *DOSBase);
  32.  
  33.  
  34. int __saveds Start(char *arg)
  35. {
  36.     struct ExecBase *SysBase;
  37.     struct DosLibrary *DOSBase;
  38.     struct muBase *muBase = NULL;
  39.     struct RDArgs *args;
  40.     LONG argarray[] = {
  41.         NULL, NULL, NULL, NULL
  42.     };
  43.     ULONG flags = NULL;
  44.     int rc = RETURN_ERROR;
  45.     struct TagItem tags[3];
  46.  
  47.     SysBase = *(struct ExecBase **)4;
  48.  
  49.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  50.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))) {
  51.         rc = ERROR_INVALID_RESIDENT_LIBRARY;
  52.         goto Exit;
  53.     }
  54.  
  55.     args = ReadArgs("FLAGS,GROUP/K,OTHER/K,GLOBAL/S", argarray, NULL);
  56.     if (!args)
  57.         PrintFault(IoErr(), NULL);
  58.     else if (!((argarray[0] && !ProcessFlags((char *)argarray[0], &flags,
  59.                                                           FLAGS_OWNER, DOSBase)) ||
  60.                   (argarray[1] && !ProcessFlags((char *)argarray[1], &flags,
  61.                                                           FLAGS_GROUP, DOSBase)) ||
  62.                   (argarray[2] && !ProcessFlags((char *)argarray[2], &flags,
  63.                                                           FLAGS_OTHER, DOSBase)))) {
  64.         flags ^= FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
  65.         tags[0].ti_Tag = muT_DefProtection;
  66.         tags[0].ti_Data = (LONG)flags;
  67.         tags[1].ti_Tag = muT_Global;
  68.         tags[1].ti_Data = (BOOL)argarray[3];
  69.         tags[2].ti_Tag = TAG_DONE;
  70.         if (muSetDefProtectionA(tags))
  71.             rc = RETURN_OK;
  72.         else
  73.             PutStr("SetDefProtect failed\n");
  74.     }
  75.     FreeArgs(args);
  76.  
  77. Exit:
  78.     CloseLibrary((struct Library *)muBase);
  79.     CloseLibrary((struct Library *)DOSBase);
  80.  
  81.     return(rc);
  82. }
  83.  
  84.  
  85. static BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type,
  86.                                               struct DosLibrary *DOSBase)
  87. {
  88.     int i;
  89.     BOOL rc = TRUE;
  90.  
  91.     for (i = 0; str[i] && rc; i++) {
  92.         switch(str[i]) {
  93.             case 's':
  94.             case 'S':
  95.                 if (type == FLAGS_OWNER)
  96.                     *flags |= FIBF_SCRIPT;
  97.                 else
  98.                     goto Error;
  99.                 break;
  100.  
  101.             case 'p':
  102.             case 'P':
  103.                 if (type == FLAGS_OWNER)
  104.                     *flags |= FIBF_PURE;
  105.                 else
  106.                     goto Error;
  107.                 break;
  108.  
  109.             case 'a':
  110.             case 'A':
  111.                 if (type == FLAGS_OWNER)
  112.                     *flags |= FIBF_ARCHIVE;
  113.                 else
  114.                     goto Error;
  115.                 break;
  116.  
  117.             case 'r':
  118.             case 'R':
  119.                 if (type == FLAGS_OWNER)
  120.                     *flags |= FIBF_READ;
  121.                 else if (type == FLAGS_GROUP)
  122.                     *flags |= FIBF_GRP_READ;
  123.                 else
  124.                     *flags |= FIBF_OTR_READ;
  125.                 break;
  126.  
  127.             case 'w':
  128.             case 'W':
  129.                 if (type == FLAGS_OWNER)
  130.                     *flags |= FIBF_WRITE;
  131.                 else if (type == FLAGS_GROUP)
  132.                     *flags |= FIBF_GRP_WRITE;
  133.                 else
  134.                     *flags |= FIBF_OTR_WRITE;
  135.                 break;
  136.  
  137.             case 'e':
  138.             case 'E':
  139.                 if (type == FLAGS_OWNER)
  140.                     *flags |= FIBF_EXECUTE;
  141.                 else if (type == FLAGS_GROUP)
  142.                     *flags |= FIBF_GRP_EXECUTE;
  143.                 else
  144.                     *flags |= FIBF_OTR_EXECUTE;
  145.                 break;
  146.  
  147.             case 'd':
  148.             case 'D':
  149.                 if (type == FLAGS_OWNER)
  150.                     *flags |= FIBF_DELETE;
  151.                 else if (type == FLAGS_GROUP)
  152.                     *flags |= FIBF_GRP_DELETE;
  153.                 else
  154.                     *flags |= FIBF_OTR_DELETE;
  155.                 break;
  156.  
  157.             default:
  158.             Error:
  159.                 rc = FALSE;
  160.                 PutStr("Invalid flag - must be one of ");
  161.                 if (type == FLAGS_OWNER)
  162.                     PutStr("SPARWED\n");
  163.                 else
  164.                     PutStr("RWED\n");
  165.                 break;
  166.         }
  167.     }
  168.  
  169.     return(rc);
  170. }
  171.